export const npuaFalse = () => {
  return {
    null: false,
    primaryKey: false,
    unsigned: false,
    autoIncrement: false
  }
}

/**
 * 所有 Input 支持的类型对应的数据字段类型等数据（默认/示例设计）
 */
export const fieldData = {
  string: {
    type: 'varchar',
    length: 255,
    precision: 0,
    defaultType: 'EMPTY STRING',
    ...npuaFalse()
  },
  password: {
    type: 'varchar',
    length: 32,
    precision: 0,
    defaultType: 'EMPTY STRING',
    ...npuaFalse()
  },
  number: {
    type: 'int',
    length: 11,
    precision: 0,
    default: '0',
    defaultType: 'INPUT',
    ...npuaFalse(),
    desc: '后缀为number, int, num，或者类型为bigint, int, mediumint, smallint, tinyint, decimal, double, float会自动转换'
  },
  radio: {
    type: 'enum',
    length: 0,
    precision: 0,
    defaultType: 'NULL',
    ...npuaFalse(),
    desc: '类型为enum，或类型为tinyint(1)、char(1)、tinyint(1) unsigned并且后缀为：status, state, type自动转换'
  },
  checkbox: {
    type: 'set',
    length: 0,
    precision: 0,
    defaultType: 'NULL',
    ...npuaFalse(),
    desc: "类型为：set('1','2')，备注格式：名称:1=选项1,2=选项2"
  },
  switch: {
    type: 'tinyint',
    length: 1,
    precision: 0,
    default: '0',
    defaultType: 'INPUT',
    ...npuaFalse(),
    unsigned: true,
    desc: "类型为：'tinyint', 'int', 'enum',后缀为：'switch', 'toggle'"
  },
  textarea: {
    type: 'varchar',
    length: 255,
    precision: 0,
    defaultType: 'EMPTY STRING',
    ...npuaFalse(),
    desc: '后缀为：textarea, multiline, rows，并且类型为varchar的数据表，或者类型为：longtext, text, mediumtext, smalltext, tinytext, bigtext'
  },
  array: {
    type: 'varchar',
    length: 255,
    precision: 0,
    defaultType: 'EMPTY STRING',
    ...npuaFalse()
  },
  json: {
    type: 'text',
    length: 0,
    precision: 0,
    defaultType: 'NULL',
    modelType: 'json',
    ...npuaFalse(),
    null: true
  },
  datetime: {
    type: 'int',
    length: 11,
    precision: 0,
    defaultType: 'NULL',
    ...npuaFalse(),
    null: true
  },
  timestamp: {
    type: 'timestamp',
    length: 0,
    precision: 0,
    defaultType: 'NULL',
    ...npuaFalse(),
    null: true,
    desc: '类型为:int,datetime, timestamp，后缀为：datetime会自动转换'
  },
  year: {
    type: 'year',
    length: 4,
    precision: 0,
    defaultType: 'NULL',
    ...npuaFalse(),
    null: true,
    desc: '类型为:year，会自动转换'
  },
  date: {
    type: 'date',
    length: 0,
    precision: 0,
    defaultType: 'NULL',
    ...npuaFalse(),
    null: true,
    desc: '类型为:date，会自动转换'
  },
  time: {
    type: 'time',
    length: 0,
    precision: 0,
    defaultType: 'NULL',
    ...npuaFalse(),
    null: true,
    desc: '类型为:time，后缀为time'
  },
  select: {
    type: 'enum',
    length: 0,
    precision: 0,
    defaultType: 'NULL',
    ...npuaFalse(),
    null: true,
    desc: '类型为:int/enum，后缀为select, list, data'
  },
  selects: {
    type: 'varchar',
    length: 255,
    precision: 0,
    defaultType: 'EMPTY STRING',
    ...npuaFalse(),
    desc: '类型为:varchar，后缀为selects, multi, lists，字段类型转换为：json'
  },
  remoteSelect: {
    type: 'int',
    length: 10,
    precision: 0,
    default: '0',
    defaultType: 'NULL',
    ...npuaFalse(),
    null: true,
    unsigned: true
  },
  remoteSelects: {
    type: 'varchar',
    length: 255,
    precision: 0,
    defaultType: 'EMPTY STRING',
    ...npuaFalse()
  },
  editor: {
    type: 'text',
    length: 0,
    precision: 0,
    defaultType: 'NULL',
    ...npuaFalse(),
    null: true,
    desc: '类型为：longtext, text, mediumtext, smalltext, tinytext, bigtext，或后缀为：content, editor'
  },
  city: {
    type: 'varchar',
    length: 100,
    precision: 0,
    defaultType: 'EMPTY STRING',
    ...npuaFalse()
  },
  image: {
    type: 'varchar',
    length: 255,
    precision: 0,
    defaultType: 'EMPTY STRING',
    ...npuaFalse(),
    desc: '类型不限制，后缀为：image,avatar则会自动转换'
  },
  images: {
    type: 'varchar',
    length: 1500,
    precision: 0,
    defaultType: 'EMPTY STRING',
    ...npuaFalse(),
    modelType: 'json',
    desc: '类型不限制，后缀为：images,avatars则会自动转换，字段类型转换为：json'
  },
  file: {
    type: 'varchar',
    length: 255,
    precision: 0,
    defaultType: 'EMPTY STRING',
    ...npuaFalse(),
    desc: '类型不限制，后缀为：file则会自动转换'
  },
  files: {
    type: 'varchar',
    length: 1500,
    precision: 0,
    modelType: 'json',
    defaultType: 'EMPTY STRING',
    ...npuaFalse(),
    desc: '类型不限制，后缀为：files则会自动转换，字段类型转换为：json'
  },
  audio: {
    type: 'varchar',
    length: 255,
    precision: 0,
    defaultType: 'EMPTY STRING',
    ...npuaFalse(),
    desc: '类型不限制，后缀为：audio则会自动转换'
  },
  audios: {
    type: 'varchar',
    length: 1500,
    precision: 0,
    modelType: 'json',
    defaultType: 'EMPTY STRING',
    ...npuaFalse(),
    desc: '类型不限制，后缀为：audios则会自动转换，字段类型转换为：json'
  },
  video: {
    type: 'varchar',
    length: 255,
    precision: 0,
    defaultType: 'EMPTY STRING',
    ...npuaFalse(),
    desc: '类型不限制，后缀为：video则会自动转换'
  },
  videos: {
    type: 'varchar',
    length: 1500,
    precision: 0,
    modelType: 'json',
    defaultType: 'EMPTY STRING',
    ...npuaFalse(),
    desc: '类型不限制，后缀为：videos则会自动转换，字段类型转换为：json'
  },
  icon: {
    type: 'varchar',
    length: 50,
    precision: 0,
    defaultType: 'EMPTY STRING',
    ...npuaFalse(),
    desc: '类型不限制，后缀为:icon'
  },
  color: {
    type: 'varchar',
    length: 50,
    precision: 0,
    defaultType: 'EMPTY STRING',
    ...npuaFalse(),
    desc: '后缀为color自动转换'
  }
}

// 表格渲染
export const tableRenderOption = [
  { value: 'customRender', label: '自定义渲染组件' },
  { value: 'slot', label: '使用插槽' },
  { label: '图片', value: 'image' },
  { label: '图标', value: 'icon' },
  { label: '开关', value: 'switch' },
  { label: '多图片', value: 'images' },
  { label: '标签', value: 'tag' },
  { label: '多标签', value: 'tags' },
  { label: '链接', value: 'url' },
  { label: '日期时间', value: 'datetime' },
  { label: '时间', value: 'time' },
  { label: '年份', value: 'year' },
  { label: '复制', value: 'copy' },
  { label: '颜色', value: 'color' }
]

// 表单渲染
export const formRenderOption = [
  { label: '复选框', value: 'checkbox' },
  { label: '开关', value: 'switches' },
  { label: '富文本', value: 'dkTinyEditor' },
  { label: '多行文本', value: 'textarea' },
  { label: '时间', value: 'time' },
  { label: '日期时间', value: 'dateTime' },
  { label: '日期', value: 'date' },
  { label: '年份', value: 'year' },
  { label: '单选', value: 'select' },
  { label: '多选', value: 'selects' },
  { label: '远程单选', value: 'remoteSelect' },
  { label: '远程多选', value: 'remoteSelects' },
  { label: '城市选择', value: 'city' }, // 废弃
  { label: '单图上传', value: 'dkImage' },
  { label: '多图上传', value: 'dkImageList' },
  { label: '文件上传', value: 'file' },
  { label: '多文件上传', value: 'files' },
  { label: '图标选择', value: 'DkIconInput' },
  { label: '单选框', value: 'radio' },
  { label: '数字输入', value: 'number' },
  { label: '颜色选择', value: 'color' },
  { label: '链接地址', value: 'url' }
]

export const designTypeOptions = [
  { label: '默认', value: 'default', table: {} },
  { label: '主键', value: 'pk', table: { width: 70, sortable: true } },
  { label: '权重', value: 'weigh' },
  { label: '时间戳', value: 'timestamp', table: { width: 150, render: 'datetime', operator: 'RANGE' } },
  { label: '字符串', value: 'string', table: { operator: 'LIKE' } },
  { label: '密码', value: 'password', table: { operator: 'false' } },
  { label: '数字', value: 'number', table: { operator: 'RANGE', sortable: true } },
  { label: '浮点数', value: 'float', table: { operator: 'RANGE', sortable: true }, form: { validator: ['float'] } },
  { label: '单选', value: 'radio', table: { render: 'tag' }, form: {} },
  { label: '多选', value: 'checkbox', table: { render: 'tags', operator: 'FIND_IN_SET' }, form: {} },

  { label: '开关', value: 'switches', table: { render: 'switches' }, form: { render: 'switches' } },

  { label: '多行文本', value: 'textarea', table: { filter: true, operator: 'false' }, form: { rows: 3 } },
  { label: '数组', value: 'array', table: { filter: true, operator: 'false' }, form: {} },
  {
    label: '日期时间',
    value: 'datetime',
    table: { operator: 'eq', width: 150, sortable: true },
    form: { validator: ['date'] }
  },
  { label: '年份', value: 'year', table: { operator: 'RANGE', sortable: true }, form: { validator: 'date' } },
  { label: '日期', value: 'date', table: { operator: 'eq', sortable: true }, form: {} },
  { label: '时间', value: 'time', table: { operator: 'eq', sortable: true }, form: {} },
  { label: '下拉选择', value: 'select', table: { render: 'tag' }, form: {} },
  { label: '下拉选择(多选)', value: 'selects', table: { render: 'tags', operator: 'FIND_IN_SET' }, form: {} },
  { label: '下拉选择(远程)', value: 'remoteSelect', table: {}, form: {} },
  { label: '下拉选择(远程多选)', value: 'remoteSelects', table: {}, form: {} },
  { label: '富文本', value: 'editor', table: { filter: true, operator: false }, form: {} },
  { label: '图片上传', value: 'image', table: { render: 'image', operator: false }, form: {} },
  { label: '多图上传', value: 'images', table: { render: 'images', operator: false }, form: {} },
  { label: '文件上传', value: 'file', table: { render: 'file', operator: false }, form: {} },
  { label: '多文件上传', value: 'files', table: { render: 'files', operator: false }, form: {} },
  { label: '图标', value: 'icon', table: { render: 'icon', operator: false }, form: {} },
  { label: '颜色', value: 'color', table: { render: 'color', operator: false }, form: {} }
]

export const commonFields = [
  {
    label: '系统字段',
    fields: [
      {
        title: '主键',
        name: 'id',
        comment: 'ID',
        designType: 'pk',
        formBuildExclude: true,
        table: {},
        form: {},
        ...fieldData.number,
        defaultType: 'NONE',
        primaryKey: true,
        unsigned: true,
        autoIncrement: true
      },
      {
        title: '平台ID',
        name: 'plaid',
        comment: '平台ID',
        designType: 'number',
        table: {},
        form: {},
        ...fieldData.number,
        unsigned: true
      },
      {
        title: '小程序ID',
        name: 'appid',
        comment: '小程序ID',
        designType: 'number',
        table: {},
        form: {},
        ...fieldData.number,
        unsigned: true
      },
      {
        title: '权重（拖拽排序）',
        name: 'weigh',
        comment: '权重',
        designType: 'weigh',
        table: {},
        form: {},
        ...fieldData.number,
        default: '0',
        defaultType: 'INPUT',
        null: false
      },
      {
        title: '更新时间',
        name: 'update_time',
        comment: '更新时间',
        designType: 'timestamp',
        table: {},
        form: {},
        ...fieldData.datetime
      },
      {
        title: '创建时间',
        name: 'create_time',
        comment: '创建时间',
        designType: 'timestamp',
        table: {},
        form: {},
        ...fieldData.datetime
      },
      {
        title: '删除时间',
        name: 'delete_time',
        comment: '删除时间',
        designType: 'timestamp',
        table: {},
        form: {},
        ...fieldData.datetime
      },
      {
        title: '系统配置',
        name: 'config',
        comment: '系统配置',
        designType: 'default',
        table: {},
        form: {},
        ...fieldData.json
      }
    ]
  },
  {
    label: '基础字段',
    fields: [
      {
        title: '单选',
        name: 'radio',
        dataType: "enum('0','1')",
        default: '',
        comment: '单选:0=选项1,1=选项2',
        ...fieldData.radio,
        designType: 'radio',
        table: {},
        form: {}
      },
      {
        title: '数字',
        name: 'number',
        comment: '数字',
        ...fieldData.number,
        designType: 'number',
        table: {},
        form: {}
      },
      {
        title: '浮点数',
        name: 'float',
        type: 'decimal',
        length: 5,
        precision: 2,
        default: '0.00',
        defaultType: 'INPUT',
        null: false,
        comment: '浮点数',
        designType: 'float',
        table: {},
        form: {},
        ...npuaFalse()
      },
      {
        title: '富文本',
        name: 'content',
        default: '',
        comment: '富文本',
        ...fieldData.editor,
        designType: 'editor',
        table: {},
        form: {}
      },
      {
        title: '多行文本',
        name: 'textarea',
        default: '',
        comment: '多行文本',
        ...fieldData.textarea,
        designType: 'textarea',
        table: {
          filter: true
        },
        form: {}
      },
      {
        title: '开关',
        name: 'switch',
        dataType: 'int',
        default: '0',
        comment: '开关',
        ...fieldData.switch,
        designType: 'switches',
        defaultType: 'INPUT',
        table: {},
        form: {}
      },
      {
        title: '复选框',
        name: 'checkbox',
        dataType: "set('0','1')",
        default: 'opt0,opt1',
        comment: '复选框:0=选项1,1=选项2',
        ...fieldData.checkbox,
        designType: 'checkbox',
        defaultType: 'INPUT',
        table: {},
        form: {}
      },
      {
        title: '下拉单选',
        name: 'select',
        dataType: "enum('0','1')",
        default: '',
        comment: '下拉单选:0=选项1,1=选项2',
        ...fieldData.select,
        designType: 'select',
        table: {},
        form: {}
      },
      {
        title: '下拉多选',
        name: 'selects',
        dataType: 'varchar',
        default: '',
        comment: '下拉多选:0=选项1,1=选项2',
        ...fieldData.selects,
        designType: 'selects',
        modelType: 'json',
        table: {},
        form: {}
      },
      {
        title: '下拉单选(远程)',
        name: 'select_id',
        default: '',
        comment: '下拉单选',
        ...fieldData.remoteSelect,
        designType: 'remoteSelect',
        table: {},
        form: {},
        unsigned: true,
        remoteConfig: {}
      },
      {
        title: '下拉多选(远程)',
        name: 'selects_ids',
        default: '',
        comment: '下拉多选',
        ...fieldData.remoteSelects,
        designType: 'remoteSelects',
        modelType: 'json',
        table: {},
        form: {}
      },
      {
        title: '图标选择器',
        name: 'icon',
        dataType: 'varchar',
        default: '',
        comment: '图标',
        ...fieldData.icon,
        designType: 'icon',
        table: {},
        form: {}
      },
      {
        title: '颜色',
        name: 'color',
        comment: '颜色',
        ...fieldData.color,
        designType: 'color',
        table: {},
        form: {}
      },
      {
        title: '链接',
        name: 'url',
        comment: '链接',
        ...fieldData.string,
        designType: 'string',
        table: {},
        form: {}
      },
      {
        title: '复制内容',
        name: 'copy',
        comment: '复制内容',
        ...fieldData.string,
        designType: 'string',
        table: {
          render: 'copy'
        },
        form: {}
      }
    ]
  },
  {
    label: '媒体字段',
    fields: [
      {
        title: '单图上传',
        name: 'image',
        dataType: 'varchar',
        default: '',
        comment: '图片',
        ...fieldData.image,
        designType: 'image',
        table: {},
        form: {}
      },
      {
        title: '多图上传',
        name: 'images',
        dataType: 'varchar',
        default: '',
        comment: '多图',
        ...fieldData.images,
        designType: 'images',
        table: {},
        form: {}
      },
      {
        title: '单文件上传',
        name: 'file',
        dataType: 'varchar',
        default: '',
        comment: '文件',
        ...fieldData.file,
        designType: 'file',
        table: {},
        form: {}
      },
      {
        title: '多文件上传',
        name: 'files',
        dataType: 'varchar',
        default: '',
        comment: '多文件',
        ...fieldData.files,
        designType: 'files',
        table: {},
        form: {}
      },
      {
        title: '单音频上传',
        name: 'audio',
        dataType: 'varchar',
        default: '',
        comment: '音频',
        ...fieldData.file,
        designType: 'audio',
        table: {},
        form: {}
      },
      {
        title: '多音频上传',
        name: 'audios',
        dataType: 'varchar',
        default: '',
        comment: '多音频',
        ...fieldData.audios,
        designType: 'audios',
        table: {},
        form: {}
      },
      {
        title: '单视频上传',
        name: 'video',
        dataType: 'varchar',
        default: '',
        comment: '视频',
        ...fieldData.video,
        designType: 'video',
        table: {},
        form: {}
      },
      {
        title: '多视频上传',
        name: 'videos',
        dataType: 'varchar',
        default: '',
        comment: '多视频',
        ...fieldData.videos,
        designType: 'videos',
        table: {},
        form: {}
      }
    ]
  },
  {
    label: '时间日期字段',
    fields: [
      {
        title: '时间日期(时间戳int)',
        name: 'check_time',
        default: '',
        comment: '时间日期',
        ...fieldData.datetime,
        designType: 'timestamp',
        modelType: '',
        table: {},
        form: {},
        desc: '类型为:int, timestamp，后缀为：datetime会自动转换'
      },
      {
        title: '时间日期(datetime)',
        name: 'check_datetime',
        default: '',
        comment: '时间日期',
        ...fieldData.datetime,
        designType: 'timestamp',
        modelType: 'timestamp',
        table: {},
        form: {},
        desc: '类型为:int,datetime, timestamp，后缀为：datetime会自动转换'
      },
      // {
      //   title: '时间日期(时间戳timestamp)',
      //   name: 'timestamp',
      //   default: '',
      //   comment: '时间日期',
      //   ...fieldData.timestamp,
      //   designType: 'timestamp',
      //   table: {},
      //   form: {}
      // },
      {
        title: '时间选择',
        name: 'time',
        default: '',
        comment: '时间',
        ...fieldData.time,
        designType: 'time',
        table: {},
        form: {}
      },
      {
        title: '日期选择',
        name: 'date',
        default: '',
        comment: '日期',
        ...fieldData.date,
        designType: 'date',
        table: {},
        form: {}
      },
      {
        title: '年份选择',
        name: 'year',
        default: '',
        comment: '年份',
        ...fieldData.year,
        designType: 'year',
        table: {},
        form: {}
      }
    ]
  },
  {
    label: '常用字段',
    fields: [
      {
        title: '用户ID',
        name: 'user_id',
        comment: '用户ID',
        designType: 'remoteSelect',
        table: {},
        form: {},
        ...fieldData.remoteSelect,
        unsigned: true,
        remoteConfig: {}
      },
      {
        title: '启用',
        name: 'enable_switch',
        dataType: 'int',
        default: '0',
        comment: '开关',
        ...fieldData.switch,
        designType: 'switches',
        defaultType: 'INPUT',
        table: {},
        form: {}
      },
      {
        title: '状态',
        name: 'radio',
        dataType: "enum('0','1','2')",
        default: '1',
        comment: '状态:0=隐藏,1=启用,2=推荐',
        ...fieldData.radio,
        defaultType: 'INPUT',
        designType: 'radio',
        table: {},
        form: {}
      },
      {
        title: '性别',
        name: 'radio',
        dataType: "enum('0','1','2')",
        default: '0',
        comment: '性别:0=未知,1=男,2=女',
        ...fieldData.radio,
        defaultType: 'INPUT',
        designType: 'radio',
        table: {},
        form: {}
      },
      {
        title: '备注',
        name: 'remark',
        comment: '备注',
        designType: 'textarea',
        table: {},
        form: {},
        ...fieldData.textarea
      },
      {
        title: '描述',
        name: 'description',
        comment: '描述',
        designType: 'textarea',
        table: {},
        form: {},
        ...fieldData.textarea
      },
      {
        title: '标题',
        name: 'title',
        comment: '标题',
        designType: 'string',
        table: {
          width: '150px'
        },
        form: {},
        ...fieldData.string,
        length: 255
      },
      {
        title: '手机号',
        name: 'phone',
        comment: '手机号',
        designType: 'string',
        table: {},
        form: {},
        ...fieldData.string,
        length: 11
      },
      {
        title: '邮箱',
        name: 'email',
        comment: '邮箱',
        designType: 'string',
        table: {},
        form: {
          validate: ['email'],
          message: '请输入正确的邮箱'
        },
        ...fieldData.string
      },
      {
        title: '用户名',
        name: 'username',
        comment: '用户名',
        designType: 'string',
        table: {},
        form: {},
        ...fieldData.string,
        length: 80
      },
      {
        title: '价格',
        name: 'price',
        type: 'decimal',
        length: 10,
        precision: 2,
        default: '0.00',
        defaultType: 'INPUT',
        ...npuaFalse(),
        comment: '价格',
        designType: 'float',
        table: {},
        form: {}
      },
      {
        title: '访问量',
        name: 'visit',
        comment: '访问量',
        ...fieldData.number,
        designType: 'number',
        table: {},
        form: {}
      },
      {
        title: '订单号',
        name: 'out_trade_no',
        comment: '订单号',
        ...fieldData.string,
        length: 64,
        designType: 'string',
        table: {},
        form: {}
      }
    ]
  }
]
